#pragma once

#include "Channel.h"
#include "EventLoop.h"
#include "InetAddress.h"
#include <functional>
#include <memory>

namespace GiSo {

class EventLoop;
class Channel;

class Acceptor {
public:
    using NewConnectionCallback = std::function<void(std::unique_ptr<Channel>,const InetAddress&)>;

    Acceptor(EventLoop* loop, const InetAddress& listenAddr); // 修改构造函数
    ~Acceptor();

    void SetNewConnectionCallback(NewConnectionCallback cb)
    {
        m_NewConnectionCallback = std::move(cb);
    }

    void Listen();

private:
    void HandleAccept();

    EventLoop* m_Loop;
    int m_AcceptSocket; // listening socket
    std::unique_ptr<Channel> m_AcceptChannel;
    NewConnectionCallback m_NewConnectionCallback;
};

} // namespace GiSo